define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cases/cases/index' + location.search,
                    // add_url: 'cases/cases/add',
                    // edit_url: 'cases/cases/edit',
                    detail_url: 'cases/cases/detail',
                    // del_url: 'cases/cases/del',
                    multi_url: 'cases/cases/multi',
                    import_url: 'cases/cases/import',
                    table: 'cases',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_shop_name', title: __('处罚商户')},
                        {field: 'cases_type_name', title: __('Cases_type_id')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'detachment_name', title: __('Detachment_id')},
                        {field: 'captain_name', title: __('Captain_id')},
                        {field: 'user_staff_name', title: __('User_staff_id')},
                        {field: 'user_staff_class_name', title: __('User_staff_class_id')},
                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        {field: 'endtime', title: __('Endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'starttime', title: __('Starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'patrol_child_id', title: __('Patrol_child_id')},
                        {field: 'accept_name', title: __('Accept_id')},
                        {field: 'verify_images', title: __('Verify_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'is_verify', title: __('Is_verify'), searchList: {"1":__('Is_verify 1'),"2":__('Is_verify 2')}, formatter: Table.api.formatter.normal},
                        {field: 'verify_money', title: __('Verify_money'), operate:'BETWEEN'},
                        {field: 'is_appear', title: __('Is_appear'), searchList: {"1":__('Is_appear 1'),"2":__('Is_appear 2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '详情',
                                    title: '详情',
                                    icon: 'fa fa-mortar-board',
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    extend:"data-area='[\"70%\",\"70%\"]'",
                                    url: "cases/cases/detail?patrol_id={row.id}",
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
